package com.kun.kaptcha.controller;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @author fangkun
 * @create 2023-05-08-10:39
 */
@RestController
public class CaptchaController {

/*    @Autowired
    DefaultKaptcha defaultKaptcha;

    @GetMapping("/textCaptcha")
    public void textCaptcha(HttpServletResponse resp) throws IOException {
        //生成验证码文本
        String text = defaultKaptcha.createText();
        //基于文本生成图片对象
        BufferedImage image = defaultKaptcha.createImage(text);
        //写到前端
        ImageIO.write(image,"jpg",resp.getOutputStream());
    }*/

    @GetMapping("/hello")
    public void hello(HttpSession session){
        System.out.println("session.getAttribute.kaptchaCode : " + session.getAttribute("kaptchaCode"));
    }
}
